﻿using System.Threading;

namespace SDT.ServiceSystem
{
    /// <summary>
    /// Written by SinhNT
    /// </summary>
    public abstract class WorkUnit : IWorkUnit
    {
        private static int UniversalId = 0;

        public WorkUnit()
        {
            id = Interlocked.Increment(ref UniversalId);
        }

        private int id = 0;
        public int Id
        {
            get { return id; }
        }

        private bool ready = true;
        public virtual bool Ready
        {
            get { return ready; }
            set 
            {
                lock (this)
                {
                    if (value == false)
                        ClearResult();
                    ready = value;
                }
            }
        }

        public abstract void ClearResult();
    }
}